package gui;

import gui.components.map.PopupMenu;
import gui.components.map.engine.RenderEngine;
import gui.components.map.engine.RenderQueueType;
import gui.components.map.objects.objProjectile;
import gui.components.map.objects.objRadialGrid;
import gui.components.map.objects.objRasterGrid;
import gui.components.map.objects.objShip;
import java.awt.BorderLayout;
import java.awt.Graphics;

import javax.swing.JPanel;

import simulation.Data;

import lookandfeel.colorScheme;

public class Map extends JPanel
{
	private static RenderEngine _renderengine;
	private static Thread _data;
	private static final long serialVersionUID = 1L;
	
	objShip _obj1 = new objShip();
	objProjectile _obj2 = new objProjectile();
	
	public Map(colorScheme laf)
	{
		// Set background color of the panel
	    this.setBackground(laf.getMapBackground());
		this.setLayout(new BorderLayout());
		
		// Add right click menu
		PopupMenu rightClick = new PopupMenu();
			rightClick.setOpaque(false);
			
			//Menu options
			rightClick.newMenuItem("Move here");
			rightClick.addSeperator();
			rightClick.newMenuItem("Missile");
			rightClick.newMenuItem("Cannon");
			rightClick.newMenuItem("Torpedo");
			rightClick.newMenuItem("Goalkeeper");
		this.add(rightClick);

		//Nieuw renderengine defineren
		_renderengine = new RenderEngine();	
		
		//Nieuw networkengine defineren
		_data = new Thread(new Data(_renderengine));
		_data.start();
	}
	public void paintComponent(Graphics g) 
	{
		 //Supertype painten
		 super.paintComponent(g);
		 
		 //Renderengine benodigde informatie geven, en starten met renderen
	     _renderengine.SetGraphicsObject(g);
		 _renderengine.StartRender(this);	
	 }
	
	public void ToggleGrid(objRadialGrid _rg)
	{
		//Bestaand grid verwijderen
		ClearGrid();
		
		//Nieuw radial grid genereren
		_rg.SetRenderEngine(_renderengine);
		_rg.SetTargetPanel(this);
		_rg.GenerateGrid(this);		
	}
	
	public void ToggleGrid(objRasterGrid _rg)
	{
		// Bestaand grid verwijderen
		ClearGrid();
		
		// Nieuw raster grid genereren
		_rg.SetRenderEngine(_renderengine);
		_rg.SetTargetPanel(this);
		_rg.GenerateGrid(this);
	}
	
	public void ToggleGrids(objRasterGrid _rtg,objRadialGrid _rdg)
	{
		// Bestaand grid verwijderen
		ClearGrid();
		ClearGrid();
		
		// Nieuw raster grid genereren
		_rtg.SetRenderEngine(_renderengine);
		_rtg.SetTargetPanel(this);
		_rtg.GenerateGrid(this);
		
		//Nieuw radial grid genereren
		_rdg.SetRenderEngine(_renderengine);
		_rdg.SetTargetPanel(this);
		_rdg.GenerateGrid(this);		
	}

	public void ClearGrid()
	{
		_renderengine.RemoveRenderQueue(RenderQueueType.GRID);
	}
}
